@echo off
echo.
echo ====================================
echo   Cyan-Note Backend Startup
echo ====================================
echo.

REM Check JAVA_HOME
if "%JAVA_HOME%"=="" (
    echo [ERROR] JAVA_HOME environment variable is not set
    echo [HINT] Please set JAVA_HOME to JDK 17 installation directory
    echo.
    echo Example:
    echo set JAVA_HOME=C:\Program Files\Java\jdk-17
    echo.
    pause
    exit /b 1
)

REM Check Java version
echo [CHECK] Java version:
"%JAVA_HOME%\bin\java" -version
echo.

REM Set Maven options
set MAVEN_OPTS=-Xmx1024m -Xms512m

REM Start Spring Boot application
echo [START] Starting Cyan-Note Backend...
echo.

REM Use Maven to start
call mvn spring-boot:run -Dspring.profiles.active=dev

REM If startup fails, show error information
if %ERRORLEVEL% neq 0 (
    echo.
    echo [ERROR] Startup failed with error code: %ERRORLEVEL%
    echo [HINT] Please check:
    echo 1. JDK 17 is properly installed
    echo 2. JAVA_HOME environment variable is set correctly
    echo 3. Maven is properly installed
    echo 4. Internet connection is available (for downloading dependencies)
    echo.
    pause
)

echo.
echo [DONE] Application stopped
pause